package jk.framework.canary.core.rule;

import jk.framework.canary.core.po.RouteContext;

import java.util.Collection;
import java.util.List;

/**
 * 规则执行链
 *
 * @author cuichao
 */
public abstract class AbstractRuleChain<T> implements RouteRuleChain {

    /**
     * 初始化职责链
     * @return
     */
    protected abstract List<RouteRule<T>> initRuleChain();

    @Override
    public boolean isAllow(RouteContext context) {
        //初始化ruleChain
        Collection<RouteRule<T>> ruleChain = initRuleChain();

        for (RouteRule routeRule : ruleChain) {
            if (!routeRule.isAllow(context) ){
                return false;
            }
        }
        return true;
    }

}
